package cn.com.action;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.opensymphony.xwork2.ActionSupport;

import cn.com.biz.PexaminationFormBiz;
import cn.com.entity.PexaminationForm;

public class PexaminationFormAction extends ActionSupport implements Serializable,SessionAware {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private PexaminationFormBiz pexaminationformbiz;
	private Map<String, Object> session;
	private PexaminationForm pexaminationform;
	private String pexaminationformmsg;
	private int consumerid;
	public int getConsumerid() {
		return consumerid;
	}
	public void setConsumerid(int consumerid) {
		this.consumerid = consumerid;
	}
	public String getPexaminationformmsg() {
		return pexaminationformmsg;
	}
	public void setPexaminationformmsg(String pexaminationformmsg) {
		this.pexaminationformmsg = pexaminationformmsg;
	}
	public PexaminationForm getPexaminationform() {
		return pexaminationform;
	}
	public void setPexaminationform(PexaminationForm pexaminationform) {
		this.pexaminationform = pexaminationform;
	}
	public PexaminationFormBiz getPexaminationformbiz() {
		return pexaminationformbiz;
	}
	public void setPexaminationformbiz(PexaminationFormBiz pexaminationformbiz) {
		this.pexaminationformbiz = pexaminationformbiz;
	}
	public Map<String, Object> getSession() {
		return session;
	}
	@Override
	public void setSession(Map<String, Object> arg0) {
		// TODO Auto-generated method stub
		
	}
	//增加体检单action
	public String addPexaminationForm(){
		@SuppressWarnings("resource")
		ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
		pexaminationformbiz=(PexaminationFormBiz)ctx.getBean("pexaminationformbiz");
		boolean bool=pexaminationformbiz.addpexaminationform(pexaminationform);
		if(bool){
			setPexaminationformmsg("预约体检成功");
			session.put("pexaminationform", pexaminationform);
			return SUCCESS;
		}else{
			setPexaminationformmsg("预约体检失败，请重新预约体检");
			return ERROR;
		}
		
	}
	//通过用户id查询体检单
	public String selectpexformbyconsumerid(){
		@SuppressWarnings("resource")
		ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
		pexaminationformbiz=(PexaminationFormBiz)ctx.getBean("pexaminationformbiz");
		List<PexaminationForm> list=pexaminationformbiz.selectPexaminationFormByid(consumerid);
		session.put("pexformbyconsumeridlist", list);
		return SUCCESS;
	}
	
	
	public String selectpexaminationform(){
		ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
		PexaminationFormBiz pexaminationformbiz=(PexaminationFormBiz)ctx.getBean("pexaminationformbiz");
		List<PexaminationForm> list=pexaminationformbiz.selectAllPexaminationForm();
		if(list.size()==1 && list!=null){
			session.put("list", list);
			System.out.println("查询成功"+list);
		}
		return SUCCESS;
	}
	
}
